home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gnome-core.idb / usr / freeware / include / applet-widget.h.z / applet-widget.h
C/C++ Source or Header  |  2002-07-08  |  11KB  |  294 lines

  1. /* applet-widget: the interface for the applets, these are the functions
  2.  * that applets need
  3.  * (C) 1998 the Free Software Foundation
  4.  *
  5.  * Author:  George Lebl
  6.  */
  7. #ifndef __APPLET_WIDGET_H__
  8. #define __APPLET_WIDGET_H__
  9.  
  10. #include <gtk/gtk.h>
  11. #include <gnome.h>
  12. #include <libgnorba/gnorba.h>
  13.  
  14. #include <gnome-panel.h>
  15.  
  16. #define HAVE_SAVE_SESSION_SIGNAL 1
  17. #define HAVE_APPLET_BIND_EVENTS 1
  18. #define HAVE_PANEL_PIXEL_SIZE 1
  19. #define HAVE_PANEL_DRAW_SIGNAL 1
  20. #define HAVE_APPLET_QUEUE_RESIZE 1
  21. #define HAVE_APPLET_SIZE_ULTRA_TINY_AND_RIDICULOUS 1
  22.  
  23. BEGIN_GNOME_DECLS
  24.  
  25. typedef GNOME_Panel_OrientType PanelOrientType;
  26. #define ORIENT_UP GNOME_Panel_ORIENT_UP
  27. #define ORIENT_DOWN GNOME_Panel_ORIENT_DOWN
  28. #define ORIENT_LEFT GNOME_Panel_ORIENT_LEFT
  29. #define ORIENT_RIGHT GNOME_Panel_ORIENT_RIGHT
  30.  
  31. enum {
  32.     PIXEL_SIZE_ULTRA_TINY = 12,
  33.     PIXEL_SIZE_TINY = 24,
  34.     PIXEL_SIZE_SMALL = 36,
  35.     PIXEL_SIZE_STANDARD = 48,
  36.     PIXEL_SIZE_LARGE = 64,
  37.     PIXEL_SIZE_HUGE = 80,
  38.     PIXEL_SIZE_RIDICULOUS = 128
  39. };
  40.  
  41. typedef GNOME_Panel_BackType PanelBackType;
  42. #define PANEL_BACK_NONE GNOME_Panel_BACK_NONE
  43. #define PANEL_BACK_COLOR GNOME_Panel_BACK_COLOR
  44. #define PANEL_BACK_PIXMAP GNOME_Panel_BACK_PIXMAP
  45. #define PANEL_BACK_TRANSLUCENT GNOME_Panel_BACK_TRANSLUCENT
  46.  
  47.  
  48. #define TYPE_APPLET_WIDGET          (applet_widget_get_type ())
  49. #define APPLET_WIDGET(obj)          GTK_CHECK_CAST (obj, applet_widget_get_type (), AppletWidget)
  50. #define APPLET_WIDGET_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, applet_widget_get_type (), AppletWidgetClass)
  51. #define IS_APPLET_WIDGET(obj)       GTK_CHECK_TYPE (obj, applet_widget_get_type ())
  52.  
  53. typedef struct _AppletWidgetPrivate    AppletWidgetPrivate;
  54.  
  55. typedef struct _AppletWidget        AppletWidget;
  56. typedef void (*AppletCallbackFunc)(AppletWidget *applet, gpointer data);
  57.  
  58. struct _AppletWidget
  59. {
  60.     GtkPlug            window;
  61.     
  62.     /*< public >*/
  63.     char            *privcfgpath;
  64.     char            *globcfgpath;
  65.     
  66.     /* you should really use the accessors for these anyway */
  67.     PanelOrientType        orient;            
  68.     int            size;            
  69.     
  70.     /*< private >*/
  71.     AppletWidgetPrivate    *_priv;
  72. };
  73.  
  74. typedef struct _AppletWidgetClass    AppletWidgetClass;
  75. struct _AppletWidgetClass
  76. {
  77.     GtkPlugClass parent_class;
  78.  
  79.     /* when the orientation of the parent panel changes, you should 
  80.        connect this signal before doing applet_widget_add so that
  81.        you get an initial change_orient signal during the add, so
  82.        that you can update your orientation properly */
  83.     void (* change_orient) (AppletWidget *applet,
  84.                 GNOME_Panel_OrientType orient);
  85.     /* the panel background changes, the pixmap handeling is likely
  86.        to change */
  87.     void (* back_change) (AppletWidget *applet,
  88.                   GNOME_Panel_BackType type,
  89.                   char *pixmap,
  90.                   GdkColor *color);
  91.     /*will send the current state of the tooltips, if they are enabled
  92.       or disabled, you should only need this if you are doing something
  93.       weird*/
  94.     void (* tooltip_state) (AppletWidget *applet,
  95.                 int enabled);
  96.     /*when the panel wants to save a session it will call this signal 
  97.       if you trap it make sure you do gnome_config_sync() and
  98.       gnome_config_drop_all() after your done otherwise the changes
  99.       might not be written to file, also make sure you return
  100.       FALSE from this signal or your position wil not get saved!*/
  101.     gboolean (* save_session) (AppletWidget *applet,
  102.                    char *cfgpath,
  103.                    char *globcfgpath);
  104.     /*when the position changes and we selected to get this signal,
  105.       it is sent so that you can move some external window along with
  106.       the applet, it is not normally sent, so you need to enable it
  107.       with the applet_widget_send_position*/
  108.     void (* change_position) (AppletWidget *applet,
  109.                   int x, int y);
  110.  
  111.     /* when the panel size changes, semantics are the same as above */
  112.     void (* change_pixel_size) (AppletWidget *applet,
  113.                     int size);
  114.     
  115.     /* done when we are requesting draws, only useful if you want
  116.        to get rgb data of the background to draw yourself on, this
  117.        signal is called when that data would be different and you
  118.        should reget it and redraw, you should use the
  119.        applet_widget_get_rgb_bg function to get rgb background for
  120.        you to render on, you need to use applet_widget_send_draw 
  121.        to enable this signal */
  122.     void (* do_draw) (AppletWidget *applet);
  123. };
  124.  
  125. typedef GtkWidget *(*AppletFactoryActivator)(const char *goad_id, const char **params, int nparams);
  126. /* Returns TRUE if the factory can activate this applet */
  127. typedef gboolean (*AppletFactoryQuerier)(const char *goad_id);
  128.  
  129. guint        applet_widget_get_type        (void) G_GNUC_CONST;
  130.  
  131. void            applet_factory_new(const char *goad_id,
  132.                    AppletFactoryQuerier qfunc,
  133.                    AppletFactoryActivator afunc);
  134. GtkWidget*    applet_widget_new(const char *goad_id);
  135.  
  136. void        applet_widget_construct(AppletWidget* applet, const char *goad_id);
  137.  
  138. /*set tooltip over the applet, NULL to remove a tooltip*/
  139. void        applet_widget_set_tooltip    (AppletWidget *applet,
  140.                          const char *text);
  141.  
  142. /*set tooltip on a specific widget inside the applet*/
  143. void        applet_widget_set_widget_tooltip(AppletWidget *applet,
  144.                          GtkWidget *widget,
  145.                          const char *text);
  146.  
  147. /* add a widget to the plug and register the applet, this has to
  148.    be done after all the children had been added so that the applet-lib
  149.    can bind the events over them so that peoplce can move them with
  150.    the second button, get the menu, etc ...*/
  151. void        applet_widget_add        (AppletWidget *applet,
  152.                          GtkWidget *widget);
  153. /* this function is the same as above, but you can select if the events
  154.    are actually bound, most applet writers can use the above, this is
  155.    just for very special cases*/
  156. void        applet_widget_add_full        (AppletWidget *applet,
  157.                          GtkWidget *widget,
  158.                          gboolean bind_events);
  159.  
  160. /* bind the events for button2 and button3 on a widget, this is useful
  161.    when you are added a new widget and want the right click menu and middle
  162.    button move events to work on it*/
  163. void        applet_widget_bind_events    (AppletWidget *applet,
  164.                          GtkWidget *widget);
  165.  
  166. /* remove the plug from the panel, this will destroy the applet */
  167. void        applet_widget_remove        (AppletWidget *applet);
  168.  
  169. /* The callback functions control the applet's right click menu, the name
  170.    is just a string, which has to be unique and which controls the nesting,
  171.    for example a name of "foo/bar" will add an item to the submenu
  172.    identified by "/foo" (which you should have created before with
  173.    register_callback_dir, use this for properies callback, help, about,
  174.    etc... etc...
  175. */
  176. /*add a callback onto the applet's right click menu*/
  177. void        applet_widget_register_callback    (AppletWidget *applet,
  178.                          const char *name,
  179.                          const char *menutext,
  180.                          AppletCallbackFunc func,
  181.                          gpointer data);
  182. void        applet_widget_register_stock_callback    (AppletWidget *applet,
  183.                              const char *name,
  184.                              const char *stock_type,
  185.                              const char *menutext,
  186.                              AppletCallbackFunc func,
  187.                              gpointer data);
  188.  
  189. /*remove a menuitem*/
  190. void        applet_widget_unregister_callback (AppletWidget *applet,
  191.                            const char *name);
  192.  
  193. /*add a submenu*/
  194. void        applet_widget_register_callback_dir (AppletWidget *applet,
  195.                              const char *name,
  196.                              const char *menutext);
  197. void        applet_widget_register_stock_callback_dir (AppletWidget *applet,
  198.                                const char *name,
  199.                                const char *stock_type,
  200.                                const char *menutext);
  201. /*remove a submenu*/
  202. void        applet_widget_unregister_callback_dir (AppletWidget *applet,
  203.                                const char *name);
  204.  
  205. /*enable/disable a menu entry*/
  206. void        applet_widget_callback_set_sensitive    (AppletWidget *applet,
  207.                              const char *name,
  208.                              gboolean sensitive);
  209.  
  210. /*get thenumber of applets*/
  211. int        applet_widget_get_applet_count    (void);
  212.  
  213. /*tell the panel to save our session here (just saves no shutdown),
  214.   this should be done when you change some of your config and want
  215.   the panel to save it's config, you should NOT call this in the
  216.   session_save handler as it will result in a locked panel*/
  217. void        applet_widget_sync_config    (AppletWidget *applet);
  218.  
  219. /* Get the orientation the applet should use */
  220. PanelOrientType    applet_widget_get_panel_orient    (AppletWidget *applet);
  221.  
  222. /* Get the pixel size the applet should use */
  223. int        applet_widget_get_panel_pixel_size    (AppletWidget *applet);
  224.  
  225. /* Get the free space for the applet if it's on an edge panel or 0
  226.    if on a packed panel or on error */
  227. int        applet_widget_get_free_space    (AppletWidget *applet);
  228.  
  229. /* sets if the change_position signal is sent*/
  230. void        applet_widget_send_position    (AppletWidget *applet,
  231.                          gboolean enable);
  232.  
  233. /* sets if the do_draw signal is sent*/
  234. void        applet_widget_send_draw        (AppletWidget *applet,
  235.                          gboolean enable);
  236.  
  237. /* gets the rgb background, useful in conjunction with the do_draw signal */
  238. void        applet_widget_get_rgb_bg    (AppletWidget *applet,
  239.                          guchar **rgb,
  240.                          int *w, int *h,
  241.                          int *rowstride);
  242.  
  243. /* queue resize on the socket in the panel for shlib applets or
  244.    just the applet for external applets */
  245. void        applet_widget_queue_resize    (AppletWidget *applet);
  246.  
  247. /*use this instead of gnome init*/
  248. gboolean    applet_widget_init        (const char *app_id,
  249.                          const char *app_version,
  250.                          int argc,
  251.                          char **argv,
  252.                          struct poptOption *options,
  253.                          unsigned int flags,
  254.                          poptContext *return_ctx);
  255.  
  256. /*abort the applet loading, once applet has been created, this is a way to
  257.   tell the panel to forget about us if we decide we want to quit before
  258.   we add the actual applet to the applet-widget*/
  259. void        applet_widget_abort_load    (AppletWidget *applet);
  260.  
  261. /* use this as gtk_main in applets */
  262. void        applet_widget_gtk_main        (void);
  263.  
  264. /*quit the applet*/
  265. void        applet_widget_gtk_main_quit    (void);
  266.  
  267. /*quit the panel (this will log out the gnome session)*/
  268. void        applet_widget_panel_quit    (void);
  269.  
  270. /* Used by shlib applets */
  271. CORBA_Object applet_widget_corba_activate(GtkWidget *applet,
  272.                       PortableServer_POA poa,
  273.                       const char *goad_id,
  274.                       const char **params,
  275.                       gpointer *impl_ptr,
  276.                       CORBA_Environment *ev);
  277.  
  278. void applet_widget_corba_deactivate(PortableServer_POA poa,
  279.                     const char *goad_id,
  280.                     gpointer impl_ptr,
  281.                     CORBA_Environment *ev);
  282.  
  283.  
  284. #define APPLET_ACTIVATE(func, goad_id, apldat) { CORBA_Environment ev; CORBA_exception_init(&ev); \
  285. CORBA_Object_release(func(CORBA_ORB_resolve_initial_references(gnome_CORBA_ORB(), \
  286. "RootPOA", &ev), goad_id, NULL, apldat, &ev), &ev); CORBA_exception_free(&ev); }
  287.  
  288. #define APPLET_DEACTIVATE(func, goad_id, apldat) { CORBA_Environment ev; CORBA_exception_init(&ev); \
  289. func(CORBA_ORB_resolve_initial_references(gnome_CORBA_ORB(), "RootPOA", &ev), goad_id, apldat, &ev); CORBA_exception_free(&ev); }
  290.  
  291. END_GNOME_DECLS
  292.  
  293. #endif /* __APPLET_WIDGET_H__ */
  294.